$webwork.htmlEncode($page.space.name) : MySQL DataStore
This page last changed on Mar 29, 2007 by m_oconnor.
MySQLInstallationFirst, download the 'geoserver-XXX-mysql-plugin.zip' from the GeoServer project downloads page: http://sourceforge.net/project/showfiles.php?group_id=25086 Unzip this and place the jarfiles in your GeoServer installation's geoserver/WEB-INF/lib directory, then restart GeoServer. (NOTE: To get our MySQL datastore to 'see' the tables properly, it was necessary to copy the mysql-connector-java-3.0.17.jar file despite Tomcat already having a MySQL connector library - Tomcat's connector was not able to detect 'geometry' columns.) Data Set ConfigurationThe MySQL DataStore should now show up as an option when creating a new DataStore (Welcome -> Config -> Data -> Stores -> New in the web admin). Select it as an option, and fill out the name field. The following screen allows you to enter the basic connection details that GeoServer will use to access MySQL:
In this case, our database is called 'vista' and hosted on the local machine. Make sure the user you specify has read/write access to the tables you intend to source your geospatial data from! Click 'Submit', then 'Apply' and 'Save' to make the datastore available. Table StructureBefore you can create a feature type from your MySQL datastore, you will need to create a database table to contain your geospatial data (assuming you don't have one already). The following SQL will create an appropriately-typed table: CREATE TABLE `geoserver_test` (
`the_geom` geometry NOT NULL,
`fid` varchar(255) NOT NULL,
`description` varchar(2000) default NULL,
PRIMARY KEY (`fid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
Feature Type ConfigurationIn the GeoServer admin console, select (Welcome -> Config -> Data -> FeatureTypes -> New) and select the appropriate table within your MySQL datastore. You'll need to enter a default style (try 'capitals'), an SRS projection code (try 4326) and click the 'Generate' button to generate an appropriate bounding box if you have existing data in the table. The other values on this screen should be OK, just click 'Submit', then 'Apply' and 'Save' to make the feature available. The new feature should now respond with XML if you hit the URL: http://localhost:8080/geoserver/wfs?request=getfeature&service=wfs&version=1.0.0&typename=vista:geoserver_test
:- where 'vista' is the name of the datastore and 'geoserver_test' is the name of your feature type. Known BugsWhen creating a new FeatureType be sure that the table has a primary key. Testing with MySQL seems to reveal that both the WMS and WFS work. MySQL is not SRS aware, which is a blocker in gt2 but I just used 4326, and everything seemed to go fine. A bit of a hiccup with MapPreview stuff, but lead to the fixing of a little bugger in the codebase.
|
![]() |
Document generated by Confluence on Jan 16, 2008 23:27 |